package com.huawei.hwCloudJs.d;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.os.Build.VERSION;
import android.os.Looper;
import android.text.TextUtils;
import android.util.Log;
import android.webkit.WebView;
import java.util.Locale;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

public class a {
    public static String a(WebView webView) {
        if (webView == null) {
            return "";
        }
        if (Looper.myLooper() != Looper.getMainLooper()) {
            return b(webView);
        }
        try {
            return webView.getUrl();
        } catch (Exception e) {
            Log.e("getWebViewUrl", "getWebViewUrl myLooper Exception" + e.getMessage());
            return "";
        }
    }

    public static boolean a() {
        Context a = com.huawei.hwCloudJs.b.a.a();
        if (a == null) {
            return true;
        }
        ConnectivityManager connectivityManager = (ConnectivityManager) a.getSystemService("connectivity");
        NetworkInfo activeNetworkInfo = connectivityManager != null ? connectivityManager.getActiveNetworkInfo() : null;
        boolean z = activeNetworkInfo != null && activeNetworkInfo.isAvailable();
        return z;
    }

    public static String b() {
        return VERSION.RELEASE;
    }

    private static String b(final WebView webView) {
        final CountDownLatch countDownLatch = new CountDownLatch(1);
        final String[] strArr = new String[]{null};
        try {
            Log.i("getWebViewUrl", " webView post");
            webView.post(new Runnable() {
                public void run() {
                    Log.i("getWebViewUrl", " webView getUrl");
                    strArr[0] = webView.getUrl();
                    if (TextUtils.isEmpty(strArr[0])) {
                        Log.e("getWebViewUrl", "webView getUrl isEmpty");
                    }
                    countDownLatch.countDown();
                }
            });
            Log.i("getWebViewUrl", " webView await");
            if (!countDownLatch.await(500, TimeUnit.MILLISECONDS)) {
                Log.i("getWebViewUrl", " webView await false");
            }
        } catch (InterruptedException e) {
            Log.e("getWebViewUrl", "latch.await InterruptedException" + e.getMessage());
        } catch (Exception e2) {
            Log.e("getWebViewUrl", "getWebViewUrl Exception" + e2.getMessage());
        }
        return strArr[0];
    }

    public static String c() {
        return Build.MODEL;
    }

    public static String d() {
        return Build.DISPLAY;
    }

    public static String e() {
        return Locale.getDefault().getLanguage();
    }

    public static String f() {
        return Locale.getDefault().getCountry();
    }
}
